/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.common.session.stateless;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import merlion.common.entity.GlobalVariable;

/**
 *
 * @author Kenn
 */
@Stateless
public class GlobalVariableSessionBean implements GlobalVariableSessionBeanLocal {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    @PersistenceContext
    private EntityManager entityManager;
    
    @Override
    public GlobalVariable getGlobalVariableByKey(String key){
        return (GlobalVariable) entityManager.createQuery("SELECT gv FROM GlobalVariable gv WHERE gv.globalKey LIKE '" + key + "'").getResultList().get(0);
    }
    
    @Override
    public GlobalVariable updateGlobalVariable(GlobalVariable gr){
        return entityManager.merge(gr);
    }
}
